package com.yanqu.road.server.gameplayer.module.activity;

import com.yanqu.road.pb.cross3.server.CrossChannelServerProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.manger.cross3.ChannelActivityMgr;
import com.yanqu.road.server.manger.cross3.GameXServerNameMgr;
import com.yanqu.road.server.protocol.ClientProtocol;

import java.util.ArrayList;
import java.util.Set;

public class ChannelActivityModule extends GeneralModule {

    public ChannelActivityModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public void loginSendMsg() {
//        syncCrossChannelServerName();
    }

    public void syncCrossChannelServerName() {
        boolean needAll = true; // 合渠道需求,发所有服务器名称
        if (WasheMgr.getWasheConfig() != null) {
            needAll = true;
        }

        CrossChannelServerProto.ServerNameListMsg.Builder builder;
        if (needAll) {
            builder = GameXServerNameMgr.getServerNameMap().getAllServerNameMsg();
        } else {
            Set<Long> serverIdSet = ChannelActivityMgr.getServerIdSet();
            builder = GameXServerNameMgr.getServerNameMap().getServerNameMsg(new ArrayList<>(serverIdSet));
        }

//        // 去掉自己渠道的
//        int channelId = ServerListMgr.getServerInfo(GameServer.getInstance().getServerId()).getChannelId();
//        for (int i = 0; i < builder.getNameListList().size(); i++) {
//            if (builder.getNameList(i).getChannelId() == channelId) {
//                builder.removeNameList(i);
//                i--;
//            }
//        }

        player.sendPacket(ClientProtocol.U_SYNC_CHANNEL_SERVER_NAME, builder);
    }
}
